package com.qfedu.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.dao.SkillDao;
import com.qfedu.entity.ResponseData;
import com.qfedu.entity.Skill;
import com.qfedu.service.SkillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class SkillServiceImpl implements SkillService {
    @Autowired
    private SkillDao skillDao;
    @Override
    public ResponseData<List<Skill>> findAllSkill(int pageIndex, int pageSize) {
        PageHelper.startPage(pageIndex,pageSize);
        List<Skill> skillList = skillDao.findAllSkill();
        PageInfo pageInfo = new PageInfo(skillList);
        int count = (int) pageInfo.getTotal();
        ResponseData<List<Skill>> responseData = new ResponseData<>();
        responseData.setCode(0);
        responseData.setData(skillList);
        responseData.setCount(count);
        responseData.setMsg("ok");
        return responseData;

    }

    @Override
    public boolean addSkill(Skill skill) {
        int result = skillDao.addSkill(skill);
        if(result > 0){
            return true;
        }
        return false;
    }


}
